package com.aaa.filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

@WebFilter(filterName = "LogFilter",urlPatterns = "/*")
public class LogFilter implements Filter {
    @Override
    public void init(FilterConfig config) throws ServletException {
    }
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        String method=request.getParameter("method");
        HttpServletRequest httpServletRequest=(HttpServletRequest) request;
        Object username=httpServletRequest.getSession().getAttribute("username");
        if(null!=method){
            System.out.println("日志：用户"+username+new Date()+"执行力"+method);
        }
        chain.doFilter(request, response);
    }
}
